package CRM_UI;

import DAO.DAOEmpleado;
import DAO.DAOOportunidadNegocio;
import LogicaNegocio.Empleado;
import LogicaNegocio.OportunidadNegocio;
import java.util.Vector;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GestionarON_UI.java
 *
 * Created on 9/06/2009, 04:25:09 PM
 */

/**
 *
 * @author L¡z
 */
public class GestionarON_UI extends javax.swing.JFrame {

    OportunidadNegocio oportunidad;
    String perfil;
    String cc_empleado = "";

    Vector <Vector> onTabla;
    Vector <String> nombresColumnas;

    /** Creates new form GestionarON_UI */
    public GestionarON_UI(JFrame parent, String perfil, String cc) {
        initComponents();
        if(parent != null) {
            parent.setVisible(false);
        }
        setLocationRelativeTo(null);
        
        this.perfil = perfil;
        inicializarRepresentantes();
        if(!perfil.equals("jefe")) {
            jButton1.setVisible(false);
            jButton3.setVisible(false);
            jLabel3.setVisible(false);
            jComboBox4.setVisible(false);
        }
        else {
            jButton4.setVisible(false);
        }
        setCedulaEmpleado(cc);

        onTabla = new Vector <Vector>();

        incializarColumnas();
        consultarOportunidades();
        actualizarTabla();
    }

    public void actualizarTabla()
    {
        jTable1.setModel(new DefaultTableModel(onTabla, nombresColumnas));
    }

    public void incializarColumnas()
    {
        nombresColumnas = new Vector <String> ();
        nombresColumnas.addElement("Identificador");
        nombresColumnas.addElement("Descripción");
        nombresColumnas.addElement("Estado");
        nombresColumnas.addElement("Nivel");
        nombresColumnas.addElement("Fecha Inicio");
        nombresColumnas.addElement("Fecha Fin");
        nombresColumnas.addElement("Calificación");
        nombresColumnas.addElement("Cliente");
    }

    public void setCedulaEmpleado(String cc) {
        cc_empleado = cc;
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jPanel2 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jComboBox2 = new javax.swing.JComboBox();
        jComboBox3 = new javax.swing.JComboBox();
        jButton2 = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jComboBox5 = new javax.swing.JComboBox();
        jComboBox6 = new javax.swing.JComboBox();
        jComboBox7 = new javax.swing.JComboBox();
        jComboBox8 = new javax.swing.JComboBox();
        jComboBox9 = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        jComboBox11 = new javax.swing.JComboBox();
        jButton3 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jComboBox4 = new javax.swing.JComboBox();
        jButton4 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Gestionar Oportunidad de Negocio");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Oportunidades de Negocio"));

        jTable1.setModel(new DefaultTableModel(onTabla, nombresColumnas)/*new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null}
            },
            new String [] {
                "Identificador", "Descripción", "Estado", "Nivel", "Fecha Inicio", "Fecha Finalización", "Calificación", "Cliente"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        }*/);
        jTable1.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jScrollPane2.setViewportView(jScrollPane1);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 469, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(15, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Modificar"));

        jButton1.setText("Crear");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel1.setText("Identificador:");

        jLabel2.setText("Descripción:");

        jLabel4.setText("Nivel de Prioridad:");

        jTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1ActionPerformed(evt);
            }
        });

        jLabel5.setText("Fecha de Inicio:");

        jLabel6.setText("Fecha de Finalización:");

        jLabel7.setText("Calificación:");

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" }));

        jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1980", "1981", "1982", "1983", "1984", "1985", "1986", "1987", "1988", "1989", "1990", "1991", "1992", "1993", "1994", "1995", "1996", "1997", "1998", "1999", "2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009" }));
        jComboBox3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox3ActionPerformed(evt);
            }
        });

        jButton2.setText("Modificar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane3.setViewportView(jTextArea1);

        jComboBox5.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));

        jComboBox6.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" }));

        jComboBox7.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1980", "1981", "1982", "1983", "1984", "1985", "1986", "1987", "1988", "1989", "1990", "1991", "1992", "1993", "1994", "1995", "1996", "1997", "1998", "1999", "2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009" }));
        jComboBox7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox7ActionPerformed(evt);
            }
        });

        jComboBox8.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Baja", "Normal", "Alta" }));

        jComboBox9.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Excelente", "Buena", "Regular", "Mala" }));

        jLabel8.setText("Estado:");

        jComboBox11.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Iniciado", "Negocio ganado", "Negocio perdido" }));

        jButton3.setText("Eliminar");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jLabel3.setText("Representante de Ventas:");

        jComboBox4.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jButton4.setText("Registrar Acción");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap(36, Short.MAX_VALUE)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel8)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5)
                            .addComponent(jLabel6)
                            .addComponent(jLabel7)
                            .addComponent(jLabel3)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(29, 29, 29)
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE)
                        .addComponent(jButton3)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton4))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jComboBox5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBox6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBox7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jComboBox9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(61, 61, 61))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(jComboBox11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(jComboBox8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(11, 11, 11)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(jComboBox5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jComboBox6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jComboBox7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(51, 51, 51)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(jComboBox4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton1)
                            .addComponent(jButton4)
                            .addComponent(jButton3)
                            .addComponent(jButton2)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(155, 155, 155)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(jComboBox9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(26, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // Eliminar
        String id, descripcion, estado, prioridad, fechaInicio, fechaFin, calificacion, repVentas;
        if(perfil.equals("jefe")) {
            id = jTextField1.getText();
            descripcion = jTextArea1.getText();
            estado = (String)jComboBox11.getSelectedItem();
            prioridad = (String)jComboBox8.getSelectedItem();
            fechaInicio = (String)jComboBox1.getSelectedItem() + "/";
            fechaInicio += (String)jComboBox2.getSelectedItem() + "/";
            fechaInicio += (String)jComboBox3.getSelectedItem();
            fechaFin = (String)jComboBox5.getSelectedItem() + "/";
            fechaFin += (String)jComboBox6.getSelectedItem() + "/";
            fechaFin += (String)jComboBox7.getSelectedItem();
            calificacion = (String)jComboBox9.getSelectedItem();
            repVentas = (String)jComboBox4.getSelectedItem();

            OportunidadNegocio op = new OportunidadNegocio(id, descripcion, estado, prioridad, fechaInicio, fechaFin, calificacion, "",repVentas);
            DAOOportunidadNegocio dao = new DAOOportunidadNegocio();

            int resultado = dao.eliminarOportunidadNegocio(op.getIdCasoSC());
            if(resultado == -1) {
                JOptionPane.showMessageDialog(this, "No se pudo eliminar la oportunidad de negocio: " + op.getIdCasoSC() + " con éxito.", "Eliminar", JOptionPane.ERROR_MESSAGE);
            } else {
                JOptionPane.showMessageDialog(this, "Se pudo eliminar la oportunidad de negocio: " + op.getIdCasoSC() + " con éxito.", "Eliminar", JOptionPane.INFORMATION_MESSAGE);
            }
        }
}//GEN-LAST:event_jButton3ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // Crear (Por qué el jefe puede crear oportunidades?)

        // Aquí no se puede colocar el id del cliente porque no se puede obtener de ninguna forma.
        // El método no funciona porque tiene una llave foránea a cliente, y el jefe no puede ingresar el id del cliente.

        String id, descripcion, estado, prioridad, fechaInicio, fechaFin, calificacion, repVentas;
        id = jTextField1.getText();
        descripcion = jTextArea1.getText();
        estado = (String)jComboBox11.getSelectedItem();
        prioridad = (String)jComboBox8.getSelectedItem();
        fechaInicio = (String)jComboBox1.getSelectedItem() + "/";
        fechaInicio += (String)jComboBox2.getSelectedItem() + "/";
        fechaInicio += (String)jComboBox3.getSelectedItem();
        fechaFin = (String)jComboBox5.getSelectedItem() + "/";
        fechaFin += (String)jComboBox6.getSelectedItem() + "/";
        fechaFin += (String)jComboBox7.getSelectedItem();
        calificacion = (String)jComboBox9.getSelectedItem();
        repVentas = (String)jComboBox4.getSelectedItem();

        OportunidadNegocio op = new OportunidadNegocio(id, descripcion, estado, prioridad, fechaInicio, fechaFin, calificacion, "",repVentas);
        DAOOportunidadNegocio dao = new DAOOportunidadNegocio();

        int resultado = dao.guardarOportunidadNegocio(op);
        if(resultado == -1) {
            JOptionPane.showMessageDialog(this, "No se pudo crear la oportunidad de negocio: " + op.getIdCasoSC() + " con éxito.", "Crear", JOptionPane.ERROR_MESSAGE);
        } else {
            JOptionPane.showMessageDialog(this, "Se pudo crear la oportunidad de negocio: " + op.getIdCasoSC() + " con éxito.", "Crear", JOptionPane.INFORMATION_MESSAGE);
        }
}//GEN-LAST:event_jButton1ActionPerformed

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_jTextField1ActionPerformed

    private void jComboBox3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox3ActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_jComboBox3ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // Modificar
        String id, descripcion, estado, prioridad, fechaInicio, fechaFin, calificacion, repVentas;
        id = jTextField1.getText();
        descripcion = jTextArea1.getText();
        estado = (String)jComboBox11.getSelectedItem();
        prioridad = (String)jComboBox8.getSelectedItem();
        fechaInicio = (String)jComboBox1.getSelectedItem() + "/";
        fechaInicio += (String)jComboBox2.getSelectedItem() + "/";
        fechaInicio += (String)jComboBox3.getSelectedItem();
        fechaFin = (String)jComboBox5.getSelectedItem() + "/";
        fechaFin += (String)jComboBox6.getSelectedItem() + "/";
        fechaFin += (String)jComboBox7.getSelectedItem();
        calificacion = (String)jComboBox9.getSelectedItem();
        repVentas = (String)jComboBox4.getSelectedItem();

        OportunidadNegocio op = new OportunidadNegocio(id, descripcion, estado, prioridad, fechaInicio, fechaFin, calificacion, "",repVentas);
        DAOOportunidadNegocio dao = new DAOOportunidadNegocio();

        int resultado = dao.modificarDescripcionOportunidadNegocio(op);
        if(resultado == -1) {
            JOptionPane.showMessageDialog(this, "No se pudo modificar la oportunidad de negocio: " + op.getIdCasoSC() + " con éxito.", "Modificar", JOptionPane.ERROR_MESSAGE);
        } else {
            resultado = dao.modificarEstadoOportunidadNegocio(op);
            if(resultado == -1) {
                JOptionPane.showMessageDialog(this, "No se pudo modificar la oportunidad de negocio: " + op.getIdCasoSC() + " con éxito.", "Modificar", JOptionPane.ERROR_MESSAGE);
            } else {
                resultado = dao.modificarNivelPrioridadOportunidadNegocio(op);
                if(resultado == -1) {
                    JOptionPane.showMessageDialog(this, "No se pudo modificar la oportunidad de negocio: " + op.getIdCasoSC() + " con éxito.", "Modificar", JOptionPane.ERROR_MESSAGE);
                } else {
                    resultado = dao.modificarFechaInicioOportunidadNegocio(op);
                    if(resultado == -1) {
                        JOptionPane.showMessageDialog(this, "No se pudo modificar la oportunidad de negocio: " + op.getIdCasoSC() + " con éxito.", "Modificar", JOptionPane.ERROR_MESSAGE);
                    } else {
                        resultado = dao.modificarFechaFinalizacionOportunidadNegocio(op);
                        if(resultado == -1) {
                            JOptionPane.showMessageDialog(this, "No se pudo modificar la oportunidad de negocio: " + op.getIdCasoSC() + " con éxito.", "Modificar", JOptionPane.ERROR_MESSAGE);
                        } else {
                            resultado = dao.modificarCalificacionOportunidadNegocio(op);
                            if(resultado == -1) {
                                JOptionPane.showMessageDialog(this, "No se pudo modificar la oportunidad de negocio: " + op.getIdCasoSC() + " con éxito.", "Modificar", JOptionPane.ERROR_MESSAGE);
                            } else {
                                resultado = dao.modificarIdEmpleadoOportunidadNegocio(op);
                                if(resultado == -1) {
                                    JOptionPane.showMessageDialog(this, "No se pudo modificar la oportunidad de negocio: " + op.getIdCasoSC() + " con éxito.", "Modificar", JOptionPane.ERROR_MESSAGE);
                                } else {
                                    JOptionPane.showMessageDialog(this, "Se pudo modificó la oportunidad de negocio: " + op.getIdCasoSC() + " con éxito.", "Modificar", JOptionPane.INFORMATION_MESSAGE);
                                    consultarOportunidades();
                                    actualizarTabla();
                                }
                            }
                        }
                    }
                }
            }
        }
}//GEN-LAST:event_jButton2ActionPerformed

    private void jComboBox7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox7ActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_jComboBox7ActionPerformed

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
        // Click sobre la tabla;
        DAOOportunidadNegocio dao = new DAOOportunidadNegocio();
        oportunidad = dao.consultarOportunidadNegocio((String)jTable1.getValueAt(jTable1.getSelectedRow(), 0));

        jTextField1.setText(oportunidad.getIdCasoSC());
        jTextArea1.setText(oportunidad.getDescripcionCasoSC());
        jComboBox11.setSelectedItem(oportunidad.getEstadoCasoSC());
        jComboBox8.setSelectedItem(oportunidad.getNivelPrioridadCasoSC());


        /*jComboBox1.setSelectedItem(oportunidad.getEstadoCasoSC());
        jComboBox2.setSelectedItem(oportunidad.getEstadoCasoSC());      Todavía no sé si se usará un combo box editable.
        jComboBox3.setSelectedItem(oportunidad.getEstadoCasoSC());*/

        /*jComboBox5.setSelectedItem(oportunidad.getEstadoCasoSC());
        jComboBox6.setSelectedItem(oportunidad.getEstadoCasoSC());      Todavía no sé si se usará un combo box editable.
        jComboBox7.setSelectedItem(oportunidad.getEstadoCasoSC());*/

        jComboBox9.setSelectedItem(oportunidad.getCalificacionCasoSC());
        jComboBox4.setSelectedItem(oportunidad.getCcEmpleado());
    }//GEN-LAST:event_jTable1MouseClicked

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        
        RegistrarAccionUI obj = new RegistrarAccionUI("Ventas", oportunidad.getIdCasoSC());
        obj.setVisible(true);
    }//GEN-LAST:event_jButton4ActionPerformed

    private void consultarOportunidades() {
        onTabla.clear();

        DAOOportunidadNegocio dao = new DAOOportunidadNegocio();
        Vector<OportunidadNegocio> oportunidades = null;
        if(perfil.equals("jefe"))
            oportunidades = dao.consultarOportunidadesNegocio();
        else if(!cc_empleado .equals(""))
            oportunidades = dao.consultarOportunidadesNegocioPorRepresentante(cc_empleado);
        for(int i = 0; i < oportunidades.size(); i++) {
            Vector<String> dato = new Vector<String>();
            dato.addElement(oportunidades.elementAt(i).getIdCasoSC());
            dato.addElement(oportunidades.elementAt(i).getDescripcionCasoSC());
            dato.addElement(oportunidades.elementAt(i).getEstadoCasoSC());
            dato.addElement(oportunidades.elementAt(i).getNivelPrioridadCasoSC());
            dato.addElement(oportunidades.elementAt(i).getFechaInicioCasoSC());
            dato.addElement(oportunidades.elementAt(i).getFechaFinalizacionCasoSC());
            dato.addElement(oportunidades.elementAt(i).getCalificacionCasoSC());
            onTabla.addElement(dato);
        }
    }

    private void inicializarRepresentantes() {
        jComboBox4.removeAllItems();
        DAOEmpleado dao = new DAOEmpleado();
        Vector<Empleado> losEmpleados = new Vector<Empleado>();
        losEmpleados = dao.consultarRrepresentanteVentas();
        for(int i = 0; i < losEmpleados.size(); i++) {
            jComboBox4.insertItemAt(losEmpleados.elementAt(i).getCcEmpleado(), i);
        }
        jComboBox4.setSelectedIndex(0);
    }

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                GestionarON_UI obj = new GestionarON_UI(null, "", "7865409871");
                obj.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox11;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JComboBox jComboBox3;
    private javax.swing.JComboBox jComboBox4;
    private javax.swing.JComboBox jComboBox5;
    private javax.swing.JComboBox jComboBox6;
    private javax.swing.JComboBox jComboBox7;
    private javax.swing.JComboBox jComboBox8;
    private javax.swing.JComboBox jComboBox9;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables

}
